package com.wanter.compage.service.impl;

import com.wanter.common.utils.ID.IDutils;
import com.wanter.compage.entity.ItemMenu;
import com.wanter.compage.mapper.ItemMenuMapper;
import com.wanter.compage.service.ItemMenuService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by er on 17-8-13.
 */
@Service
public class ItemMenuServiceImpl implements ItemMenuService {
    @Autowired
    private ItemMenuMapper itemMenuMapper;
    private final Logger logger = Logger.getLogger(this.getClass());

    @Override
    public List<ItemMenu> getWithNoLoginAllItem() {
        String keyWord = "nav_item";
        List<ItemMenu> itemMenuList = itemMenuMapper.getWithNoLogin(keyWord);
        if (logger.isInfoEnabled()) {
            logger.info("默认加载的按钮为" + itemMenuList);
        }
        return itemMenuList;

    }

    @Override
    public void addItemMenu(ItemMenu itemMenu) {
        if (StringUtils.isEmpty(itemMenu.getId())) {
            itemMenu.setId(IDutils.getUUID());
        }
        if (logger.isInfoEnabled()) {
            logger.info("创建一个链接对象" + this.getClass().getName() + itemMenu);
        }
        itemMenuMapper.insertOneMenu(itemMenu);
    }
}
